package com.facebook.drawee.drawable;

import android.graphics.Canvas;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.os.SystemClock;
import com.facebook.common.internal.Preconditions;
import com.facebook.common.internal.VisibleForTesting;

public final class AutoRotateDrawable extends ForwardingDrawable implements Runnable {
    private int mInterval;
    private boolean mClockwise;
    @VisibleForTesting private float mRotationAngle;
    private boolean mIsScheduled;

    public AutoRotateDrawable(Drawable arg2, int arg3) {
        this(arg2, arg3, (byte) 0);
    }

    private AutoRotateDrawable(Drawable drawable, int interval, byte arg4) {
        super(Preconditions.checkNotNull(drawable));
        this.mRotationAngle = 0f;
        this.mIsScheduled = false;
        this.mInterval = interval;
        this.mClockwise = true;
    }

    public final void draw(Canvas canvas) {
        int v1 = canvas.save();
        Rect v2 = this.getBounds();
        int v3 = v2.right - v2.left;
        int v4 = v2.bottom - v2.top;
        float v0 = this.mRotationAngle;
        if(!this.mClockwise) {
            v0 = 360f - this.mRotationAngle;
        }

        canvas.rotate(v0, ((float)(v3 / 2 + v2.left)), ((float)(v2.top + v4 / 2)));
        super.draw(canvas);
        canvas.restoreToCount(v1);
        if(!this.mIsScheduled) {
            this.mIsScheduled = true;
            this.scheduleSelf(((Runnable)this), SystemClock.uptimeMillis() + 20);
        }
    }

    public final void run() {
        this.mIsScheduled = false;
        this.mRotationAngle += ((float)(((int)(20f / (((float)this.mInterval)) * 360f))));
        this.invalidateSelf();
    }
}

